<?php
$featureName = '支付记录';
$permission = 'comboAllOrder';
?>
@extends('admin.tableLayout')
@section('title',$featureName)
@section('barName',$featureName)
@section('quote')
    <hr/>
   <form class="layui-form" >
        <div id="select" class="layui-inline"></div>

        <div class="layui-inline">
            <input type="text" class="layui-input" width="200px" id="datetime" name="searchTime" value="" placeholder="日期范围搜索">
        </div>
        <button lay-filter="search" class="layui-btn" id="search"><i class="fa fa-search" aria-hidden="true"></i> 查询</button>
    </form>
@endsection

@section('checkbox_btn')

@endsection
@section('toolbar')

@endsection
@section('tableRender')
    <script type="text/html" id="combo_times">
        @{{ d.combo.times }}
    </script>
    <script>
        layui.use(['table','jquery','form'], function(){
            var table = layui.table;
            var $=layui.jquery;
            var form=layui.form;
            var category_id=$("#category_id").val();
            var _renderLoad = layer.msg('正在查找{{$featureName}}，请稍候',{icon: 16,time:false,shade:0.8});
            var render=table.render({
                elem:"#table",
                page:true,
                id:'idTest',
                url:'{{route($routePrefix.'.Ajax')}}',
                where:{
                    searchTime:$("input[name='searchTime']").val(),
                },
                height:400,
                cols:  [[ //标题栏
                    {field: 'id', title: 'ID', width: 80,fixed:true}
                    ,{field: 'combo_name', title: '套餐', width: 150},
                    {field: 'combo', title: '{{config('wallet.wallet.wallet_spots')}}（{{config('wallet.unit.wallet_spots')}}）', width: 100,templet:'#combo_times'},
                    {field:'member_name',title:'用户昵称',width:100},
                    {field:'price',title:'金额（￥）',width:200},
                    {field: 'created_at', title: '充值时间', width: 200},
                    //这里的toolbar值是模板元素的选择器
                ]],
                response: {//返回格式自定义
                    statusName: 'code' //数据状态的字段名称，默认：code
                    ,statusCode: 0 //成功的状态码，默认：0
                    ,msgName: 'msg' //状态信息的字段名称，默认：msg
                    ,countName: 'total' //数据总数的字段名称，默认：count
                    ,dataName: 'data' //数据列表的字段名称，默认：data
                },
                done:function () {
                    layer.close(_renderLoad);
                }
            });
            $('#search').on('click',function () {
                var data = {
                    searchTime:$("input[name='searchTime']").val(),
                };
                _renderLoad = layer.msg('正在查找{{$featureName}}，请稍候',{icon: 16,time:false,shade:0.8});
                render.reload(
                    {
                        where:data
                    }
                );
                return false;
            })
            table.on('checkbox(table)', function(obj){
                //console.log(obj)
            });

            //上方
            var   active = {
                hideAll: function(){ //获取选中数据
                    var checkStatus = table.checkStatus('idTest')
                        ,data = checkStatus.data;
                    var str=[];
                    if(data==''){
                        layer.msg('请选中所删除的行',{icon:5})
                        return false;
                    }
                    for(var i=0;i<data.length;i++){
                        str.push(data[i].id);
                    }

                    layer.confirm('是否隐藏所选',function(index) {

                        $.get('{{route($routePrefix,['act'=>'hide'])}}', {id: str,type:1}, function (obj) {
                            if (obj.info == 'success') {
                                layer.msg('操作成功', {icon: 1});
                                render.reload();
                            } else {
                                layer.msg('网络繁忙', {icon: 5});
                            }

                        })
                    })

                },
                showAll: function(){ //获取选中数目
                    var checkStatus = table.checkStatus('idTest')
                        ,data = checkStatus.data;
                    var str=[];
                    if(data==''){
                        layer.msg('请选中所要显示的记录',{icon:5})
                        return false;
                    }
                    for(var i=0;i<data.length;i++){
                        str.push(data[i].id);
                    }
                    layer.confirm('是否将选中的显示',function(index){
                        layer.close(index);
                        //服务端发送审核指令
                        $.get('{{route($routePrefix,['act'=>'show'])}}',{id:str,type:1},function(obj){
                            if(obj.info=='success'){
                                layer.msg('操作成功',{icon:1});
                                render.reload();
                            }else{
                                layer.msg('网络繁忙',{icon:5});
                            }

                        })
                    });

                }
                ,isAll: function(){ //验证是否全选
                    var checkStatus = table.checkStatus('idTest');
                    layer.msg(checkStatus.isAll ? '全选': '未全选')
                }
            };
            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            table.on('edit(table)', function(obj){ //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
                $.get('{{route($routePrefix,['act'=>'sortCol'])}}',{id:obj.data.id,sort:obj.value},function (e) {
                },'json')
            });
            table.on('tool(table)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                 if(layEvent === 'hide'){
                    layer.confirm('是否隐藏',function(index){
                        layer.close(index);
                        //服务端发送审核指令
                        $.get('{{route($routePrefix,['act'=>'draft'])}}',{id:data.id},function(e){
                            if(e.info=='success'){
                                layer.msg('操作成功',{icon:1});
                                render.reload();
                            }else{
                                layer.msg('网络繁忙',{icon:5});
                            }

                        })
                    });

                }else if(layEvent=='show'){
                    layer.confirm('是否显示',function(index){
                        layer.close(index);
                        //服务端发送审核指令
                        $.get('{{route($routePrefix,['act'=>'show'])}}',{id:data.id},function(e){
                            if(e.info=='success'){
                                layer.msg('操作成功',{icon:1});
                                render.reload();
                            }else{
                                layer.msg('网络繁忙',{icon:5});
                            }

                        })
                    });
                }else if(layEvent=='read'){

                     $(window).one("resize",function(){
                             var _url = '/admin/business/comboOrder/read/'+data.id;
                             var index = layui.layer.open({
                                 title : "查看详情",
                                 type : 2,
                                 content : _url,
                                 success : function(layero, index){
                                     setTimeout(function(){
                                         layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
                                             tips: 3
                                         });
                                     },500)
                                 }
                             })
                             layui.layer.full(index);
                     }).resize();
                 }
            });
        });
    </script>
@endsection

